import Vue from 'vue'
import Router from 'vue-router'
// @ts-ignore
import Tabar from '@/views/tabar/tabar.vue'
Vue.use(Router)

const routes = [
  {
    path: '/',
    component: Tabar,
    redirect: '/home',
    name: 'Home',
    meta: {
      title: '首页'
    },
    children: [
      {
        path: '/home',
        name: 'Home',
        meta: {
          title: '首页'
        },
        // @ts-ignore
        component: () => import('../views/home/home.vue')
      },
      {
        path: '/classify',
        // @ts-ignore
        name: 'Classify',
        component: () => import('../views/classify/classify.vue'),
        meta: {
          title: '分类'
        }
      },
      {
        path: '/ShoppingCart',
        // @ts-ignore
        name: 'ShoppingCart',
        component: () => import('../views/ShoppingCart/ShoppingCart.vue'),
        meta: {
          title: '购物车'
        }
      },
      {
        path: '/User',
        // @ts-ignore
        name: 'User',
        component: () => import('../views/user/User.vue'),
        meta: {
          title: '登录页面'
        }
      }
    ]
  },
  // 搜索页
  {
    path: '/search',
    name: 'Search',
    meta: {
      title: '搜索'
    },
    component: () => import('@/views/search/search.vue')
  },
  // 登录页
  {
    path: '/login',
    name: 'Loing',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录页'
    }
  },
  // 注册页面
  {
    path: '/Registered',
    name: 'Registered',
    component: () => import('@/views/login/Registered.vue'),
    meta: {
      title: '注册'
    }
  },
  ,
  // 忘记密码
  {
    path: '/Reset',
    name: 'Reset',
    component: () => import('@/views/login/Reset.vue'),
    meta: {
      title: '忘记密码'
    }
  },
  // 修改用户信息
  {
    path: '/modify',
    name: 'Modify',
    component: () => import('@/views/login/modify/modify.vue'),
    meta: {
      title: '修改用户信息'
    }
  },
  // 首页的商品分类
  {
    path: '/goodsclass',
    name: 'Goodsclass',
    component: () => import('@/views/home/goodsclass.vue'),
    meta: {
      title: '商品分类'
    }
  },
  // 商品详情页
  {
    path: '/goodslist',
    name: 'GoodsList',
    component: () => import('@/views/goodslist/goods.vue'),
    meta: {
      title: '商品详情页'
    }
  },
  // 全部优惠券
  {
    path: '/allCoupon',
    name: 'AllCoupon',
    component: () => import('@/views/user/coupon/allCoupon.vue'),
    meta: {
      title: '全部优惠券'
    }
  },
  // 个人优惠券
  {
    path: '/mycoupon',
    name: 'Mycoupon',
    component: () => import('@/views/user/coupon/Mycoupon.vue'),
    meta: {
      title: '个人优惠券'
    }
  },
  // 我的收藏
  {
    path: '/Collection',
    name: 'Collection',
    component: () => import('@/views/user/Collection/Collection.vue'),
    meta: {
      title: '我的收藏'
    }
  },
  // 浏览历史
  {
    path: '/history',
    name: 'History',
    component: () => import('@/views/user/history/history.vue'),
    meta: {
      title: '浏览历史'
    }
  },
  // 地址管理
  {
    path: '/ress',
    name: 'Ress',
    component: () => import('@/views/user/address/ress.vue'),
    meta: {
      title: '地址管理'
    }
  },
  // 添加地址管理
  {
    path: '/address',
    name: 'AddRess',
    component: () => import('@/views/user/address/address.vue'),
    meta: {
      title: '添加地址管理'
    }
  },
  // 添加地址管理
  {
    path: '/reviseress',
    name: 'Reviseress',
    component: () => import('@/views/user/address/reviseress.vue'),
    meta: {
      title: '修改地址'
    }
  },
  // 全部评论
  {
    path: '/appraise',
    name: 'Appraise',
    component: () => import('@/views/goodslist/appraise.vue'),
    meta: {
      title: '全部评论'
    }
  },
  // 店铺
  {
    path: '/shop',
    name: 'Shop',
    component: () => import('@/views/home/shop.vue'),
    mata: {
      title: '店铺'
    }
  },
  // 店铺
  {
    path: '/order',
    name: 'Order',
    component: () => import('@/views/goodslist/order.vue'),
    mata: {
      title: '订单'
    }
  },
  // 支付信息
  {
    path: '/payment',
    name: 'Payment',
    component: () => import('@/views/goodslist/payment.vue'),
    mata: {
      title: '支付信息'
    }
  },
  // 添加评论
  {
    path: '/rebuy',
    name: 'Rebuy',
    component: () => import('@/views/goodslist/rebuy.vue'),
    mata: {
      title: '添加评论'
    }
  },
  // 我的订单
  // 我的订单
  {
    path: '/MyOrder',
    name: 'MyOrder',
    component: () => import('@/views/user/MyOrder/MyOrder.vue'),
    mata: {
      title: '我的订单'
    }
  },
  // 查看订单
  {
    path: '/seeOreder',
    name: 'SeeOreder',
    component: () => import('@/views/user/MyOrder/seeOrder.vue'),
    mata: {
      title: '查看订单'
    }
  }
]
const router = new Router({
  mode: 'history',
  routes
})

// router.beforeEach(function(to, from, next) {
//   const token = window.localStorage.getItem('token')
//   if (to.path == '/login') {
//     if (!token) {
//       next()
//     } else {
//       next('/User')
//     }
//   }
//   next()
// })
export default router
